//
//  KShiDetaiTableCell.m
//  KCZ_B段项目
//
//  Created by dllo on 15/11/5.
//  Copyright © 2015年 Sky. All rights reserved.
//

#import "KShiDetaiTableCell.h"
#import "FitHeader.h"
#import <UIImageView+WebCache.h>
#import "FitHeader.h"
#import "FontSizeSingleTon.h"
#define FontSize [[FontSizeSingleTon shareFontSize]array]
@implementation KShiDetaiTableCell

-(void)setModel:(KShiDetailCaiModel *)model
{
    if (_model != model) {
        _model = model;
    }
    __block KShiDetaiTableCell *kdc = self;
    [_cookImage sd_setImageWithURL:[NSURL URLWithString:model.image] placeholderImage:[UIImage imageNamed:@""] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        _cookImage.image = [kdc getImageByImage:image];

    }];
    _titleLabel.text = model.title;
    _descLabel.text = model.descriptions;
    _hardLabel.text = [NSString stringWithFormat:@"难度 : %@",model.hard_level];
    _timeLabel.text = [NSString stringWithFormat:@"烹饪时间 : %@",model.cooking_time];
    _tasteLabel.text = [NSString stringWithFormat:@"口味 : %@",model.taste];
    _hardImage.image = [UIImage imageNamed:@"nandu1@2x"];
    _timeImage.image = [UIImage imageNamed:@"shijian@2x"];
    _tasteImage.image = [UIImage imageNamed:@"kouwei@2x"];
}
#pragma mark 截取部分图片方法
- (UIImage *)getImageByImage:(UIImage *)image
{
    CGRect rect = CGRectMake(0, image.size.height / 4.0, image.size.width, image.size.height / 4.0 * 2);
    CGImageRef imageRef = CGImageCreateWithImageInRect([image CGImage],rect);
    UIImage *imageResult = [UIImage imageWithCGImage:imageRef];
    return imageResult;
}
- (void)awakeFromNib {
    // Initialization code
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self creatViews];
    }
    return self;
}
-(void)layoutSubviews
{
    [super layoutSubviews];
    _cookImage.frame = CGRectMake(10 * wt, 10 * ht, 130 * wt, 100 * ht);
    _titleLabel.frame = CGRectMake(_cookImage.frame.origin.x + _cookImage.frame.size.width + 10 * wt, _cookImage.frame.origin.y, 130 * wt, 20 * ht);
    _descLabel.frame = CGRectMake(_titleLabel.frame.origin.x, _titleLabel.frame.origin.y + _titleLabel.frame.size.height + 5 * ht, _titleLabel.frame.size.width, _titleLabel.frame.size.height);
    _hardImage.frame = CGRectMake(_descLabel.frame.origin.x, _descLabel.frame.origin.y + _descLabel.frame.size.height + 5 * ht, 20 * wt, _descLabel.frame.size.height);
    _hardLabel.frame = CGRectMake(_hardImage.frame.origin.x + _hardImage.frame.size.width + 10 * wt, _hardImage.frame.origin.y, 130 * wt, _hardImage.frame.size.height);
    _timeImage.frame = CGRectMake(_hardImage.frame.origin.x, _hardImage.frame.origin.y + _hardImage.frame.size.height + 5 * ht, _hardImage.frame.size.width, _hardImage.frame.size.height);
    _timeLabel.frame = CGRectMake(_hardLabel.frame.origin.x, _hardLabel.frame.origin.y + _hardLabel.frame.size.height + 5 * ht, _hardLabel.frame.size.width, _hardLabel.frame.size.height);
    _tasteLabel.frame = CGRectMake(self.contentView.frame.size.width - 60 * wt, _hardLabel.frame.origin.y, 50 * wt, _hardLabel.frame.size.height);
    _tasteImage.frame = CGRectMake(_tasteLabel.frame.origin.x - 30, _tasteLabel.frame.origin.y, 20 * wt, 20 * ht);
}
-(void)creatViews
{
    _cookImage = [[UIImageView alloc]init];
    _cookImage.backgroundColor = [UIColor magentaColor];

    [self.contentView addSubview:_cookImage];
    
    _titleLabel = [[UILabel alloc]init];
    _titleLabel.font = [UIFont systemFontOfSize:[FontSize[1] integerValue]];
    [self.contentView addSubview:_titleLabel];
    
    _descLabel = [[UILabel alloc]init];
    _descLabel.font =[UIFont systemFontOfSize:[FontSize[2] integerValue]];
    
    [self.contentView addSubview:_descLabel];
    
    _hardImage = [[UIImageView alloc]init];
    [self.contentView addSubview:_hardImage];
    
    _hardLabel = [[UILabel alloc]init];
    _hardLabel.font = [UIFont systemFontOfSize:[FontSize[2] integerValue]];
    [self.contentView addSubview:_hardLabel];
    
    _timeImage = [[UIImageView alloc]init];
    [self.contentView addSubview:_timeImage];
    
    _timeLabel = [[UILabel alloc]init];
    _timeLabel.font = [UIFont systemFontOfSize:[FontSize[2] integerValue]];
    [self.contentView addSubview:_timeLabel];
    
    _tasteImage = [[UIImageView alloc]init];
    [self.contentView addSubview:_tasteImage];
    
    _tasteLabel = [[UILabel alloc]init];
    _tasteLabel.font = [UIFont systemFontOfSize:[FontSize[2] integerValue]];
    [self.contentView addSubview:_tasteLabel];
    
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
